/**
 编写程序，创建线程，将该线程睡眠，然后打断该线程睡眠状态，查看是否被打断。
 */
public class Test2 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            try {
                System.out.println("线程开始睡眠");
                Thread.sleep(5000); // 睡眠5秒
                System.out.println("线程正常醒来");
            } catch (InterruptedException e) {
                System.out.println("线程睡眠被打断");
                // 恢复中断状态
                Thread.currentThread().interrupt();
            }
        });

        thread.start();

        // 1秒后打断线程睡眠
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread.interrupt();

        // 检查线程是否被中断
        try {
            Thread.sleep(1000);
            System.out.println("线程是否被中断: " + thread.isInterrupted());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
